<?php
include("../safe.php");
function replace_specialChar($strParam){
    $regex = str_replace("'","''",$strParam);
    return $regex;
}
$search="";
$proname=replace_specialChar($_REQUEST["proname"]);
$code=replace_specialChar($_REQUEST["code"]);
$bname=replace_specialChar($_GET["bname"]);
$lang=replace_specialChar($_REQUEST["lang"]);
$platform=replace_specialChar($_GET["platform"]);
if($lang!==''&&isset($lang)){$search.="&lang=".$lang;}else{$lang="products";}
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
$perNumber=30;
$page=$_GET['page'];
if($_SESSION["thetype"]=="超级管理员"){$sqls="select count(*) from ph_".$lang." where 1=1";$sql="select * from ph_".$lang." where 1=1";}
if($_SESSION["thetype"]=="员工"){$sqls="select count(*) from ph_".$lang." where 1=1 and user_name='".$_SESSION["managername"]."'";$sql="select * from ph_".$lang." where 1=1 and user_name='".$_SESSION["managername"]."'";}
if($_SESSION["thetype"]=="管理员"){
$query="select admin from ph_admin where admin='".$_SESSION["managername"]."' or parent='".$_SESSION["managername"]."'";
$resulty=mysqli_query($conn,$query);
$array=array();
while($rowy = mysqli_fetch_array($resulty)){
array_push($array,"'".$rowy[admin]."'");
}
$alluser=implode(',', $array);
$sqls="select count(*) from ph_".$lang." where 1=1 and user_name in(".$alluser.")";$sql="select * from ph_".$lang." where 1=1 and user_name in(".$alluser.")";
}

if($proname!==''&&isset($proname)){$sqls.=" and proname like '%".$proname."%'";$search.="&proname=".$_REQUEST["proname"];}
if($code!==''&&isset($code)){$sqls.=" and (code ='".$code."' or skucode='".$code."')";$search.="&code=".$code;}
if($bname!==''&&isset($bname)){$sqls.=" and bname ='".$bname."'";$search.="&bname=".$_GET["bname"];}
if($platform!==''&&isset($platform)){$sqls.=" and platform ='".$platform."'";$search.="&platform=".$platform;}

$count=mysqli_query($conn,$sqls); 
$rs=mysqli_fetch_array($count); 
$totalNumber=$rs[0];
$totalPage=ceil($totalNumber/$perNumber); 
if(empty($page)){$page=1;} 
$startCount=($page-1)*$perNumber;

if($proname!==''&&isset($proname)){$sql.=" and proname like '%".$proname."%'";}
if($code!==''&&isset($code)){$sql.=" and (code ='".$code."' or skucode='".$code."')";}
if($bname!==''&&isset($bname)){$sql.=" and bname ='".$bname."'";}
if($platform!==''&&isset($platform)){$sql.=" and platform ='".$platform."'";}
$sql.=" order by ID desc limit $startCount,$perNumber";
$result=mysqli_query($conn,$sql);

$sqlm="select * from ph_lang order by id asc";
$resultm=mysqli_query($conn,$sqlm);
?> 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title><?php echo $site_name;?>后台管理-产品列表</title>
<link href="../bootstrap/css/bootstrap.min.css" title="" rel="stylesheet" />
<link href="../css/mcommon.css" rel="stylesheet" title="" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css"  />
<link rel="shortcut icon" href="/logo.ico" />
<script language="javascript">
<!--
function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
  {
  var e = form.elements[i];
  if (e.Name != "chkAll"&&e.disabled!=true)
  e.checked = form.chkAll.checked;
  }
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>
<!--顶部-->
<?php include("../top.php");?> 
<!--顶部结束--->
<!--主体部分-->
<div class="down-main">
	<!--左侧部分-->
  <?php include("../left.php");?> 
  <!--左侧部分结束-->
  <!--右侧部分-->
  <div class="right-product right-full">
  	<!--右侧内容部分-->
    <div class="container-fluid right-product-con">
    	<div class="mianbaoxie"><i class="glyphicon-folder-open glyphicon"></i>
    		<span>管理中心</span>&gt;<span>产品管理</span>&gt;<span><?php echo $_GET["bname"];?></span>&gt;<span class="dangqian">产品列表</span></div>
      <div class="container-con">
      		<!--表格-->
      		<div class="tableCon">
			<div class="tableCon-tit clear">产品列表</div>
	      		<div class="tableCon-content">
				<table width="98%" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC" class="wenzi">
      <tr>
        <td height="20" colspan="12" bgcolor="#DEDEEF"><div align="left">
          <table width="1200" border="0" cellpadding="0" cellspacing="0">
            <tr>
			
              <td><form action="productslist.php" method="post" name="form2" id="form2" class="form-inline">产品名称：
                  <input name="proname" type="text" id="proname" class="form-control" value="<?php echo $_REQUEST["proname"];?>"/>
                编号：
                  <input name="code" type="text" id="code" class="form-control" value="<?php echo $_REQUEST["code"];?>"/>
                选择语种：
                  <select name="lang" id="lang" class="form-control">   
					<?php 
					if(!empty($lang)){
					$sqlls="select *from ph_lang where lanid='".$lang."'";
					$resultts=mysqli_query($conn,$sqlls);
					if(mysqli_num_rows($resultts)>=1){
					$rowtls=mysqli_fetch_array($resultts);
					echo '<option value="'.$rowtls["lanid"].'">'.$rowtls["lang"].'</option>';
					}
					}
					?>
					<option value="products">默认语言</option>
                    <?php while($rowm=mysqli_fetch_array($resultm)){?>
                    <option value="<?php echo $rowm["lanid"];?>"><?php echo $rowm["lang"];?></option>
                    <?php }?>
                    </select>
                
                  <input  value="查询" type="submit"  class="btn btn-success form-control"/></form>                </td>
              
                
              <td><form action="proinsert.php?bname=<?php echo $bname;?>&lang=<?php echo $lang;?>&platform=<?php echo $platform;?>" method="post" enctype="multipart/form-data" name="form3" id="form3" class="form-inline">
              批量导入：
                  <input name="file1" type="file" id="file1" class="form-control" style="border:0px;"/>
                  <input  value="上传" type="submit"  class="btn btn-info form-control"/></form></td>
            </tr>
          </table>
        </div></td>
      </tr>
	  <form id="form1" name="form1" method="post" action="del_save.php?action=del&bname=<?php echo $bname;?>&lang=<?php echo $lang;?>">
      <tr>
        <td height="20" bgcolor="#FFFFFF"><div align="center">序号</div></td>
        <td bgcolor="#FFFFFF"><div align="center">产品图</div></td>
        <td bgcolor="#FFFFFF" style="width:500px;"><div align="left">产品标题</div></td>
        <td bgcolor="#FFFFFF"><div align="left">编号</div></td>
        <td bgcolor="#FFFFFF"><div align="left">售价</div></td>
        <td bgcolor="#FFFFFF"><div align="left">币种</div></td>
        <td bgcolor="#FFFFFF"><div align="left">SKU码</div></td>
        <td bgcolor="#FFFFFF"><div align="left">分类</div></td>
        <td bgcolor="#FFFFFF"><div align="left">业务员</div></td>
        <td bgcolor="#FFFFFF">所属平台</td>
        <td bgcolor="#FFFFFF"><div align="left">加入时间</div></td>
        <td bgcolor="#FFFFFF"><div align="left">操作</div></td>
      </tr>
  <?php while($row=mysqli_fetch_array($result)){
  
  ?>
      <tr>
        <td height="20" <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="center">
          <input name="id[]" type="checkbox" id="id[]" value="<?php echo $row["ID"];?>" />
        </div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><IMG height=100 src="<?php
        $imgresult=mysqli_query($conn,"select * from ph_img where id in(select imgid from(select imgid from ph_proimg where proid='".$row["ID"]."' and btid is null order by id asc) t order by id asc);");$picrow=mysqli_fetch_array($imgresult);echo $picrow["imgpath"]?>" width=115 border=1></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><A href="<?php echo $row["fromurl"];?>" target=_blank><?php echo $row["proname"];?></a></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["code"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["saleprice"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["coin"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["skucode"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["bname"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["user_name"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["platform"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><?php echo $row["ndate"];?></div></td>
        <td <?php if($row["isedit"]=='yes'){?>style="background-color:#BBF5B8"<?php }?>><div align="left"><a class="btn btn-success" role="button" href="products_edit.php?id=<?php echo $row["ID"];?>&platform=<?php echo $row["platform"];?>&bname=<?php echo $row["bname"];?>&lang=<?php echo $lang;?>&page=<?php echo $page;?>">编辑</a> <a class="btn btn-danger" role="button" href="del_save.php?action=del&id=<?php echo $row["ID"];?>&platform=<?php echo $row["platform"];?>&bname=<?php echo $row["bname"];?>&lang=<?php echo $lang;?>&page=<?php echo $page;?>">删除</a> <a class="btn btn-primary" role="button" href="fanyi.php?id=<?php echo $row["ID"];?>&platform=<?php echo $row["platform"];?>&bname=<?php echo $row["bname"];?>&lang=<?php echo $lang;?>&page=<?php echo $page;?>">一键翻译</a></div></td>
      </tr>
  <?php }?>
      <tr>
        <td bgcolor="#F7F7F7">&nbsp;</td>
        <td height="20" colspan="11" bgcolor="#F7F7F7"><div align="left">全选
          <input name="chkAll" type="checkbox" id="chkAll" onClick="CheckAll(this.form)" value="checkbox" /><input type="submit" class="btn btn-danger" value="删除选中"/><?php if(!empty($_REQUEST["bname"])&&!empty($_REQUEST["platform"])){?>
          <a class="btn btn-success" role="button" href="products_add.php?<?php echo $search;?>">新增</a> <a class="btn btn-primary" role="button" href="addtopro.php?<?php echo $search;?>">一键分配EAN/UPC码</a><?php }?></div></td>
      </tr>
      <tr>
        <td height="20" colspan="12" bgcolor="#F7F7F7"><div align="center"><?php if ($page != 1) { //页数不等于1?><a class="btn btn-primary btn-sm" role="button" href="?page=<?php echo $page - 1;echo $search;?>">上一页</a><?php }?> <!--显示上一页-->
          <?php if($page>=1+5){for($i=$page-5;$i<$page;$i++){  //循环显示出页面?><a class="btn btn-default btn-sm" role="button" href="?page=<?php echo $i;echo $search;?>"><?php echo $i ;?></a>
          <?php }}else{for($i=1;$i<$page;$i++){?><a class="btn btn-default btn-sm" role="button" href="?page=<?php echo $i;echo $search;?>"><?php echo $i ;?></a><?php }}?>
          <?php if($page>=$totalPage-5){for($i=$page;$i<=$totalPage;$i++){  //循环显示出页面?><a class="btn btn-default btn-sm" role="button" href="?page=<?php echo $i;echo $search;?>"><?php echo $i ;?></a>
          <?php }}else{for($i=$page;$i<=$page+5;$i++){?><a class="btn btn-default btn-sm" role="button" href="?page=<?php echo $i;echo $search;?>"><?php echo $i;?></a>
        <?php }}if ($page<$totalPage) { //如果page小于总页数,显示下一页链接?><a class="btn btn-default btn-sm" role="button" href="?page=<?php echo $page + 1;echo $search;?>">下一页</a><?php }?></div></td>
      </tr>
    </form>
  </table>
	      		</div>
	      	</div>
	      	<!--表格结束--->
      	</div>
      </div>
  </div>
	  <!--右侧内容部分结束-->
  </div>
  <!--右侧部分结束-->
</div>
<!--主体部分结束-->
<script src="../js/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="../bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../js/mcommon.js"></script>
</body>
</html>
